/*
 * UartContext.cpp
 *
 *  Created on: Sep 5, 2017
 *      Author: guoxs
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <termio.h>
#include <sys/ioctl.h>
#include "mycpp.h"

#include "../activity/mainActivity.h"
//void Write_txt(const char* str_flie,char* str){
//	ioutil::WriteFile(str_flie, str, strlen(str));
//}
//string Rrad_txt(const char* str_flie){
//	string content = ioutil::ReadFile(str_flie);
//	return content;
//}
//void Write_txt_float(const char* str_flie,double myfloat){
//	char T[24] = { 0 };
//	sprintf(T, "%.9f", myfloat); //产生"3.141593"
//	ioutil::WriteFile(str_flie, T, strlen(T));
//}
//void Write_txt_int(const char* str_flie,int16_t myfloat){
//	char T[24] = { 0 };
//	sprintf(T, "%d", myfloat); //产生"3.141593"
//	ioutil::WriteFile(str_flie, T, strlen(T));
//}
//double Read_txt_float(const char* str_flie){
//	char T[24] = { 0 };
//	string content = ioutil::ReadFile(str_flie);
//	for(int i=0;i<24;i++){
//		T[i]=content[i];
//	}
//	double myfloat=atof(T);//调用msumPtr控件的文本内容并转化为double类型
//	return myfloat;
//}
//
//int16_t  Read_txt_int(const char* str_flie){
//	char T[24] = { 0 };
//	string content = ioutil::ReadFile(str_flie);
//	for(int i=0;i<24;i++){
//		T[i]=content[i];
//	}
//	int16_t myfloat=atoi(T);//调用msumPtr控件的文本内容并转化为double类型
//	return myfloat;
//}

void myprintf(ZKTextView* x,const char* y,double z){
	char T[24] = { 0 };
	sprintf(T, y, z); //产生"3.141593"
	x->setText(T);
}
void myprintf(ZKEditText* x,const char* y,double z){
	char T[24] = { 0 };
	sprintf(T, y, z); //产生"3.141593"
	x->setText(T);
}

void myprintf(ZKTextView *x,double z,int y){
	char strBuf[12]={0};
	sprintf(strBuf,"%s%d%s","%.", y,"f");
	char T[24] = { 0 };
	sprintf(T, strBuf, z); //产生"3.141593"
	x->setText(T);
}

void myprintf(ZKTextView* x,int z){
	x->setText(z);
}

double myround(double x,int y){
	double mysum=x;
	for(int c=0;c<y;c++){
		mysum=mysum*10;
	}
	mysum=mysum+0.5;
	int tt=mysum;
	double mydouble=tt;
	for(int c=0;c<y;c++){
		mydouble=mydouble/10;
	}
	return mydouble;
}

void myprintf(ZKListView::ZKListSubItem* x,const char* y,double z){
	char T[24] = { 0 };
	sprintf(T, y, z); //产生"3.141593"
	x->setText(T);
}
void myprintf(ZKListView::ZKListSubItem* x,double z,int y){
	char strBuf[12]={0};
	sprintf(strBuf,"%s%d%s","%.", y,"f");
	char T[24] = { 0 };
	sprintf(T, strBuf, z); //产生"3.141593"
	x->setText(T);
}

void myprintf(ZKListView::ZKListSubItem* x,int z){
	x->setText(z);
}

void myprintf(ZKListView::ZKListSubItem* x,string z){
	x->setText(z);
}

void myprintf(ZKTextView* x,const char* y){
	x->setText(y);
}


float get_float(ZKTextView* x){
	float t2=atof(x->getText().c_str());
	return t2;
};

uint16_t get_int(ZKTextView* x){
	uint16_t t2=atoi(x->getText().c_str());
	return t2;
};

string get_txt(ZKTextView* x){
	string t2=x->getText();
	return t2;
};

//void emmc_read(uint8_t *str){
//
//	   char value[4] = {1, 2, 3, 4};
//	   VIREEPROM->Write(0, value, sizeof(value));
//};




//自己撸一个切字符串的函数.
//切字符串代码 string_cutting(string 源数据的字符串, string 开头字符串, string 开头字符串);
string string_cutting(string meat, string str0, string str1) {
	int add=str0.length();
	string str = meat;

	//找字符串的头和尾
	std::size_t found_s = str.find(str0);		//找开始位置
	 if (found_s!=std::string::npos){
		// mTextView1Ptr->setText((int)found_s);	//显示其位置     ,"error_code":0}
	 }
	 else{
		 return "beging no found";
	 }

	 //找到需要的字串结束标记
	 std::size_t found_e = str.find(str1);		//找结束位置
	 if (found_e!=std::string::npos){
		 //mTextView2Ptr->setText((int)found_e);	//显示其位置     ,"error_code":0}
		 	 	 	 	 	 	 	 	 	 	//将要的东东切出来
		 string Return_data = str.substr(found_s + add, found_e - (found_s+add));

		 return Return_data;					//将要的东东丢回去
	 }
	 else{
		 return "meat no found";
	 }
}

void delay(uint16_t x){
	Thread::sleep(x);
}

void wifiset(){
	EASYUICONTEXT->openActivity("ZKSettingActivity");
}
